//
//  CZQLiftViewController.m
//  Project_A
//
//  Created by dlios on 15-7-14.
//  Copyright (c) 2015年 zhoukaidong. All rights reserved.
//

#import "CZQLiftViewController.h"
#import "AFNetWorkHandle.h"
#import "CZQGiftViewController.h"
#import "AppDelegate.h"
#import "CZQHomeViewController.h"
#import "CZQFoodViewController.h"
#import "BaseHeader.h"
#import "CZQDigitalViewController.h"
#import "CZQEntertainmentViewController.h"
#import "CZQExerciseViewController.h"


#define WIDTH self.view.frame.size.width / 375
#define HEIGHT self.view.frame.size.height / 667

@interface CZQLiftViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *cellTextArr;
@property (nonatomic, retain) NSMutableArray *cellImageArr;
@end

@implementation CZQLiftViewController
- (void)dealloc
{
    [_tableView release];
    [_cellTextArr release];
    [_cellImageArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.cellTextArr = [@[@"主页", @"礼物", @"美食", @"数码", @"娱乐", @"运动"] mutableCopy];
    self.cellImageArr = [@[@"莱迪购", @"礼物", @"美食", @"数码", @"娱乐", @"运动"] mutableCopy];
    [self createTableView];
}


// 创建tableView
- (void)createTableView
{
    self.tableView = [[[UITableView alloc] initWithFrame:CGRectMake(0, 60 * HEIGHT, 375 * WIDTH, 607 * HEIGHT) style:UITableViewStylePlain] autorelease];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 50 * WIDTH;
    self.tableView.scrollEnabled = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cellTextArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse"] autorelease];
    }
    cell.imageView.image = [UIImage imageNamed:self.cellImageArr[indexPath.row]];
    cell.textLabel.text = self.cellTextArr[indexPath.row];
    cell.textLabel.textColor = NAVCOLOR;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        CZQHomeViewController *homeViewController = [[[CZQHomeViewController alloc] init] autorelease];
        [self setRootView:homeViewController];
        self.tabBarController.tabBar.hidden = NO;
    }
    if (indexPath.row == 1) {
        CZQGiftViewController *giftViewController = [[[CZQGiftViewController alloc] init] autorelease];
        [self setRootView:giftViewController];
        self.tabBarController.tabBar.hidden = YES;
    }
    if (indexPath.row == 2) {
        CZQFoodViewController *foodViewController = [[[CZQFoodViewController alloc] init] autorelease];
        [self setRootView:foodViewController];
        self.tabBarController.tabBar.hidden = YES;
    }
    if (indexPath.row == 3) {
        CZQDigitalViewController *digitalViewController = [[[CZQDigitalViewController alloc] init] autorelease];
        [self setRootView:digitalViewController];
        self.tabBarController.tabBar.hidden = YES;
    }
    if (indexPath.row == 4) {
        CZQEntertainmentViewController *entertainmentViewController = [[[CZQEntertainmentViewController alloc] init] autorelease];
        [self setRootView:entertainmentViewController];
        self.tabBarController.tabBar.hidden = YES;
    }
    if (indexPath.row == 5) {
        CZQExerciseViewController *exerciseViewController = [[[CZQExerciseViewController alloc] init] autorelease];
        [self setRootView:exerciseViewController];
        self.tabBarController.tabBar.hidden = YES;
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}


-(void)setRootView:(UIViewController *)vc{
    
    vc.view.backgroundColor = [UIColor whiteColor];
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    
    UITabBarController * tabBar = (UITabBarController *)[delegate tabBar];
    YRSideViewController * sideViewController = (YRSideViewController *)[delegate mySideViewController];
    
    UINavigationController *itemNav = (UINavigationController *)[delegate itemsNavi];
    UINavigationController *classsfiyNav = (UINavigationController *)[delegate classifyNavi];
    UINavigationController *userNav = (UINavigationController *)[delegate userNavi];
    
    UINavigationController *homeNav = (UINavigationController *)[delegate homeNavi];
    
    homeNav.viewControllers = @[vc];
    
    sideViewController.rootViewController = homeNav;
    
    tabBar.viewControllers = @[sideViewController,itemNav,classsfiyNav,userNav];
    
    [sideViewController hideSideViewController:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
